package com.qipay.core.help;

import com.qipay.core.entity.Result;
import com.qipay.core.utils.ThrowableUtil;

import java.util.List;

/**
 * Created by lzh on 2017/4/20 0020.
 */
public class ResultHelper {

    public static Result success() {
        Result result = new Result();
        result.setCode(Result.Status.SUCCESS);
        result.setMessage("操作成功");
        return result;
    }

    public static Result success(String message) {
        Result result = new Result();
        result.setCode(Result.Status.SUCCESS);
        result.setMessage(message);
        return result;
    }

    public static Result success(String message, Object o) {
        Result result = new Result();
        result.setCode(Result.Status.SUCCESS);
        result.setMessage(message);
        result.setResult(o);
        return result;
    }

    public static Result success(Object o) {
        Result result = new Result();
        result.setCode(Result.Status.SUCCESS);
        result.setResult(o);
        return result;
    }

    public static Result faile(String message) {
        Result result = new Result();
        result.setCode(Result.Status.FAILED);
        result.setMessage(message);
        return result;
    }

    public static Result faile(String message, String exceptionId) {
        Result result = new Result();
        result.setCode(Result.Status.FAILED);
        result.setMessage(message);
        result.setExceptionId(exceptionId);
        return result;
    }

    public static Result error(String message) {
        Result result = new Result();
        result.setCode(Result.Status.ERROR);
        result.setMessage(message);
        return result;
    }

    public static Result error(String message, String exceptionId, Throwable throwable) {
        Result result = new Result();
        result.setCode(Result.Status.ERROR);
        result.setMessage(message);
        result.setExceptionId(exceptionId);
        result.setException(ThrowableUtil.getCause(throwable));
        return result;
    }

    /**
     * 上传文件过大，异常错误说明
     *
     * @param message
     * @param exceptionId
     * @param throwable
     * @return
     */
    public static Result maxUploadSizeError(String message, String exceptionId, Throwable throwable) {
        Result result = new Result();
        result.setCode(Result.Status.ERROR);
        result.setMessage("上传文件过大，系统只支持最大为10M的文件");
        result.setExceptionId(exceptionId);
        result.setException(ThrowableUtil.getCause(throwable));
        return result;
    }

    public static Result confirm(String message) {
        Result result = new Result();
        result.setCode(Result.Status.CONFIRM);
        result.setMessage(message);
        return result;
    }

    public static Result confirm(String message, String exceptionId, List<String> keys) {
        Result result = new Result();
        result.setCode(Result.Status.CONFIRM);
        result.setMessage(message);
        result.setExceptionId(exceptionId);
        result.setKeys(keys);
        return result;
    }

    public static Result auth() {
        Result result = new Result();
        result.setCode(Result.Status.AUTH);
        result.setMessage("访问失败；原因：无权限访问该信息；建议：联系相关负责人处理");
        return result;
    }


}
